<?php
namespace Home\Controller;
use Think\Controller;

class CommonController extends Controller {

    public function _initialize()
    {
        $patha = MODULE_NAME.'/'.CONTROLLER_NAME.'/'.ACTION_NAME;
        if (in_array($patha, C('AUTH_PATHS'))) {
            if (!isset($_SESSION['id'])) {
               $this->error('未登陆，请先登陆',U('home/login/index'));
            }
        }
    }
    public function autoAdd($k,$v,$num,$id){
    	 
       $sql = "update ".$k." set ".$v." = ".$v.$num." where id='{$id}'";


       M()->execute($sql);
    }
    public function getTopview()
    {
    	// M('question')->order("order by view_num desc")->limit(10)->select();
    	// 
    	$sql = "select * from question order by view_num desc limit 10";

    	$arr =  M()->query($sql);
    	$this->assign('arr',$arr);
    }
    public function getTopanswer()
    {
    	$sql = "select * from question order by answer_num desc limit 10";

    	$row =  M()->query($sql);
    	$this->assign('row',$row);
    }
     public function getTopuser()
    {
        $sql = "select * from user order by answer_num desc limit 12";

        $rew =  M()->query($sql);
        $this->assign('rew',$rew);
    }
    public function xbs($email,$title,$content)
    {
       // require 'PHPMailerAutoload.php';
        Vendor('PHPMailer.PHPMailerAutoload');

        $mail = new \PHPMailer;

        // var_dump($mail);
        // exit;

        //$mail->SMTPDebug = 3;                               // Enable verbose debug output

        $mail->isSMTP();                                      // Set mailer to use SMTP
        $mail->Host = 'smtp.qq.com';  // Specify main and backup SMTP servers
        $mail->SMTPAuth = true;                               // Enable SMTP authentication
        $mail->Username = '2455585539@qq.com';                 // SMTP username
        $mail->Password = 'abpsbjyoacugdjbb';                           // SMTP password
        $mail->SMTPSecure = 'ssl';                            // Enable TLS encryption, `ssl` also accepted
        $mail->Port = 465;                                    // TCP port to connect to

        $mail->setFrom('2455585539@qq.com', 'abpsbjyoacugdjbb');
        $mail->addAddress($email, 'Joe User');     // Add a recipient
        // $mail->addAddress('ellen@example.com');               // Name is optional
        // $mail->addReplyTo('info@example.com', 'Information');
        // $mail->addCC('cc@example.com');
        // $mail->addBCC('bcc@example.com');

        // $mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
        // $mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name
        $mail->isHTML(true);                                  // Set email format to HTML

        $mail->Subject = $title;
        $mail->Body    = $content;
        // $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

        if(!$mail->send()) {
            echo 'Message could not be sent.';
            echo 'Mailer Error: ' . $mail->ErrorInfo;
        } else {
            echo 'Message has been sent';
        }
            }
}